package com.houg.testuserapi.service.ipml;

import com.houg.testuserapi.common.utils.Md5Utils;
import com.houg.testuserapi.mapper.UserMapper;
import com.houg.testuserapi.model.dto.UserLoginDto;
import com.houg.testuserapi.model.entity.User;
import com.houg.testuserapi.model.vo.UserVo;
import com.houg.testuserapi.service.UserService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @Author: NALHOUG
 * @Time: 2019/11/8 15:59
 * @Explain:
 */
@Service
public class UserServiceImpl implements UserService {

    @Resource
    private UserMapper userMapper;

    @Override
    public User selectByUserId(String userId) {
        return userMapper.selectByUserId(userId) ;
    }

    @Override
    public int checkByUserId(String userId) {
        return userMapper.checkByUserId(userId);
    }

    /**
     * 插入新对象
     * @param userLoginDto Dto对象
     * @return 影响行数
     */
    @Override
    public int insert(UserLoginDto userLoginDto) {
        //Md5加密
        userLoginDto.setPassword(Md5Utils.encrypt3Times(userLoginDto.getPassword()));
        //执行service
        User user = new User();
        BeanUtils.copyProperties(userLoginDto,user);
        return userMapper.insert(user);
    }

    @Override
    public int updateUser(UserVo userVo) {
        User user = new User();
        BeanUtils.copyProperties(userVo,user);
        return userMapper.update(user,null);
    }
}
